//
//  LoginController.m
//  quhuolang_service
//
//  Created by 曹欣欣 on 2018/2/9.
//  Copyright © 2018年 fusw. All rights reserved.
//

#import "LoginController.h"
#import "UIButton+Category.h"
#import "FSWSegmentedButtonView.h"
#import "FSWRegisterController.h"
#import "UIButton+Animation.h"
#import "UIButton+Gradient.h"
#import "FSWSelectBottomView.h"

@interface LoginController ()
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *zhmmLabel;
@property (weak, nonatomic) IBOutlet UIImageView *usernameImage;
@property (weak, nonatomic) IBOutlet UIImageView *pwdImageView;
@property (weak, nonatomic) IBOutlet XCBaseButton *codeBtn;

@property (weak, nonatomic) IBOutlet UITextField *userNameText;
@property (weak, nonatomic) IBOutlet UITextField *pwdText;
@property (weak, nonatomic) IBOutlet XCBaseButton *loginButton;
@property (weak, nonatomic) IBOutlet UILabel *wjmmLabel;

@property (strong, nonatomic) FSWSelectBottomView *selectView;
@property (nonatomic, strong)NSMutableArray* accountListArray;
@end

@implementation LoginController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"登录";
    @weakify(self);
    [self setNavigationRightBarItemType:OnlyHaveTitle title:@"" titleFont:16.0 titleColor:[UIColor whiteColor] image:[UIImage new] responderBlock:^{
       
    }];
    
    [self setNavigationLeftBarItemType:OnlyHaveTitle title:@"取消" titleFont:16 titleColor:[UIColor whiteColor] image:[UIImage new] responderBlock:^{
        @strongify(self);
        [self pop];
    }];
    self.pwdText.secureTextEntry = YES;
   
    // 下划线
    NSDictionary *attribtDic = @{NSUnderlineStyleAttributeName: [NSNumber numberWithInteger:NSUnderlineStyleSingle]};
    NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc]initWithString: self.zhmmLabel.text attributes:attribtDic];
    
    //赋值
    self.zhmmLabel.attributedText = attribtStr;
    
    
    
    self.zhmmLabel.userInteractionEnabled = YES;
    UITapGestureRecognizer *zhmmLabelTap = [[UITapGestureRecognizer alloc] init];
    [[zhmmLabelTap rac_gestureSignal] subscribeNext:^(id x) {
//        @strongify(self)
       
    }];
    [self.zhmmLabel addGestureRecognizer:zhmmLabelTap];
     
    [[self.userNameText rac_textSignal] subscribeNext:^(NSString* x) {
        @strongify(self)
        self.userNameText.text = x.length > 11 ? [x substringToIndex:11]: x;
        if (11 == self.userNameText.text.length && [FSWHelperTool isValidTelNum:x]) {
            self.codeBtn.enabled = YES;
        }else{
            self.codeBtn.enabled = NO;
        }
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)codeButton:(id)sender {
    @weakify(self);
    self.codeBtn.enabled = NO;

    [self.codeBtn buttonCode:60 andBlock:^{
        @strongify(self);
        self.codeBtn.enabled = YES;
    }];
    
//    NSDictionary *dict = @{@"mobile": self.mobileFieldText.text};
//    [LoginNetRequest sendCodeDataRequest:dict andBlock:^(id responseObject) {
//        @strongify(self);
//        self.codeBtn.enabled = NO;
//
//        [self.codeBtn buttonCode:60 andBlock:^{
//            @strongify(self);
//            self.codeBtn.enabled = YES;
//        }];
//    } andFailBlock:^(NSString *error) {
////        @strongify(self);
//         [FSWToast showWithText:@"发送验证码失败"];
//    }];
}

- (IBAction)submitButton:(id)sender {
//    @weakify(self);
//    if (self.userNameText.text.length <=0) {
//         [FSWToast showWithText:@"请输入用户名或者手机号"];
//        return;
//    }
//    if (self.pwdText.text.length <=0) {
//         [FSWToast showWithText:@"请输入密码"];
//        return;
//    }
    
//    NSDictionary *dict = @{@"account": self.userNameText.text,@"password":self.pwdText.text};
//    [LoginNetRequest loginRequest:dict andBlock:^(id responseObject) {
//        @strongify(self);
//        NSDictionary *dict = responseObject;
//        NSString *jpush_username = dict[@"jpush_username"];
//        if (jpush_username.length > 0) {
//            [self configJpush:jpush_username];
//        }
//        [fUserDefaults setObject:self.userNameText.text forKey:USER_MOBILE];
//        [fUserDefaults setObject:dict[@"access_token"] forKey:ACCESS_TOKEN];
//        [self dismissViewControllerAnimated:YES completion:nil];
//    } andFailBlock:^(NSString *error) {
//        
//    }];
    
    [self.accountListArray removeAllObjects];
    FSWSelectModel *pmodel1 = [[FSWSelectModel alloc]init];
    pmodel1.name = @"电子账户1";
    pmodel1.id = @"1"; 
    FSWSelectModel *pmodel2 = [[FSWSelectModel alloc]init];
    pmodel2.name = @"电子账户2";
    pmodel2.id = @"2";
    FSWSelectModel *pmodel3 = [[FSWSelectModel alloc]init];
    pmodel3.name = @"电子账户3";
    pmodel3.id = @"3";
    [self.accountListArray addObject:pmodel1];
    [self.accountListArray addObject:pmodel2];
    [self.accountListArray addObject:pmodel3];
    
    if(self.accountListArray.count > 1){
        [self showSelectView];
    }else{
        
    }
   
}


-(void)showSelectView{
    FSWSelectModel *pmodel = self.accountListArray[1];
    pmodel.isSelect = @"1";
    self.selectView = [FSWSelectBottomView footerView];
    self.selectView.isnil = 0;
    self.selectView.type = 0;
    self.selectView.titleStr = @"电子账户";
    [self.selectView show:self.accountListArray];
    @weakify(self);
    self.selectView.selectBlock = ^(NSMutableArray * _Nonnull parray) {
        @strongify(self);
        NSMutableArray *narray = [NSMutableArray array];
        NSMutableArray *iarray = [NSMutableArray array];
        for (int i = 0; i<parray.count; i++) {
            FSWSelectModel *pmodel = parray[i];
            [narray addObject:pmodel.name];
            [iarray addObject:pmodel.id];
        }
        NSString *ids = [iarray componentsJoinedByString:@","];
        NSString *names = [narray componentsJoinedByString:@","];
     
    };
}

- (NSMutableArray *)accountListArray
{
    if (!_accountListArray) {
        _accountListArray = [NSMutableArray array];
    }
    return _accountListArray;
}



@end
